package com.hhl.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hhl.dao.UserDao;
import com.hhl.entity.User;
import com.hhl.service.UserService;
import com.hhl.test01.service.UserServiceTest01;

@RestController//返回json格式
public class UserController {
	@Autowired
	UserService userService;
	@Autowired
	private UserDao userDao;
	@Autowired
	UserServiceTest01 userServiceTest01;
	
	/**
	 * template连接数据库
	 * @param name
	 * @param age
	 * @return
	 */
	@RequestMapping("addUser")
	public String addUser(String name,String age){
		userService.addUser("hhl", "18");
		return "success";
	}
	
	/**
	 * jpa连接数据库
	 * @param name
	 * @param age
	 * @return
	 */
	@RequestMapping("addJapUser")
	public String addJapUser(String name,Integer age){
		userService.addJpaUser("何海龙",18);
		return "success";
	}
	
	/**
	 * jpa连接数据库
	 * @return
	 */
	@RequestMapping("getJapUser")
	public List<User> getJapUser(){
		return userDao.findAll();
	}
	
	/**
	 * mybatis连接数据库
	 * @param name
	 * @param age
	 * @return
	 */
	@RequestMapping("addBybatisUser")
	public String addBybatisUser(String name,Integer age){
		userService.addMybatisUser("李四",28);
		return "success";
	}
	
	
	/**
	 * 多数据源时，连接多数据库
	 * @param name
	 * @param age
	 * @return
	 */
	@RequestMapping("addMybatisUser01")
	public String addMybatisUser01(String name,Integer age){
		userService.addMybatisUser01("王五",28);
		return "success";
	}
	
	@RequestMapping("addMybatisUser02")
	public String addMybatisUser02(String name,Integer age){
		userService.addMybatisUser02("赵六",28);
		return "success";
	}
	
	
	//事务控制
	@RequestMapping("addTrancation")
	public String addTrancation(String name,Integer age){
		userServiceTest01.addMybatisUser01("田七",22);
		return "success";
	}
	
	
	
	
	
	
	
	
	
}
